Skip to content

drop SubjectAs pointer-form fallback now that Parse returns values#18

Merged
hstern merged 1 commit into
mainfrom
refactor/subjectas-value-only
Jun 21, 2026
Merged

drop SubjectAs pointer-form fallback now that Parse returns values#18
hstern merged 1 commit into
mainfrom
refactor/subjectas-value-only

Conversation

@hstern

@hstern hstern commented Jun 21, 2026

Copy link
Copy Markdown
Owner

What

Removes the reflection-based pointer-form fallback from SubjectAs[T] (and the reflect import), making SubjectAs/SET.IssSub match the value form of a sub_id Subject Identifier only.

Why

Before go-subjectid v0.2.0, Parse returned the pointer form while a Go-built SET held the value form, so SubjectAs carried a reflection branch to absorb both. v0.2.0 (#17) made Parse return the value form — the same shape a Go-built SET holds — so no supported flow ever places a pointer in SET.Subject. The reflection branch is dead for every supported input.

SubjectAs is now nil guards + a single s.Subject.(T) value assertion.

Behavior change

A SET hand-built with a *subjectid.IssSubID Subject now reports ok=false from SubjectAs/IssSub instead of being dereferenced. No supported flow produces that shape (Parse yields a value; a Go-built SET should hold a value), so consumers reading parsed subjects or building value-form SETs are unaffected. A typed-nil pointer Subject still returns ok=false without panicking — the value assertion fails without touching the pointee, which is what the old !rv.IsNil() guard protected.

Changes

  • subject.go — drop the reflection block + reflect import; rewrite SubjectAs/IssSub godoc to drop the value/pointer-absorption framing.
  • secevent.go — trim the SET.Subject field doc that described the pointer form as a possible held shape.
  • example_test.go — trim ExampleSET_IssSub's value-or-pointer mention.
  • subject_test.goTestSubjectAsPointerForm (asserted pointer form IS read) → TestSubjectAsPointerFormUnmatched (asserts hand-built pointer form yields ok=false), pinning the value-only contract; the typed-nil subtest comment updated (no reflection path).
  • encode_test.go — subject literal moves to value form for suite consistency.
  • CHANGELOG.md[Unreleased]Changed entry.

Verification

Local CI mirror all green: gofmt -l, go vet ./..., go mod tidy -diff, go test -race -shuffle=on ./..., golangci-lint v2.12.2 run ./... (0 issues). Code review clean.

🤖 Generated with Claude Code

SubjectAs carried a reflection block that detected a pointer-form
Subject (*subjectid.IssSubID), dereferenced it, and re-checked against
the requested value type T. That existed to reconcile a split: before
go-subjectid v0.2.0, Parse returned the pointer form while a Go-built
SET held the value form, so the accessor had to absorb both.

v0.2.0 removed the split — Parse now returns the value form, the same
form a Go-built SET holds — so no supported flow ever places a pointer
in SET.Subject. The reflection branch is dead for every supported input
and is removed, along with the reflect import. SubjectAs is now nil
guards plus a single value-form type assertion; IssSub is unchanged
beyond the simplification it delegates to.

The one observable consequence is for a SET hand-built with a
*subjectid.IssSubID Subject: SubjectAs and IssSub now report ok=false
for it rather than dereferencing it. No supported flow produces that
shape — Parse yields a value, and a Go-built SET should hold a value —
so consumers reading parsed subjects or building value-form SETs are
unaffected. A typed-nil pointer Subject still returns ok=false without
panicking: the value-form assertion fails without touching the pointee,
which is what the old !rv.IsNil() guard protected against.

TestSubjectAsPointerForm, which asserted the pointer form WAS read,
becomes TestSubjectAsPointerFormUnmatched, asserting the hand-built
pointer form now yields ok=false — pinning the value-only contract so a
later reader doesn't mistake the removal for a regression. The doc
comments on SubjectAs, IssSub, and SET.Subject drop their value/pointer
framing, and encode_test.go's subject literal moves to the value form
so the suite is uniformly value-form.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hstern hstern merged commit 041421a into main Jun 21, 2026
4 checks passed
@hstern hstern deleted the refactor/subjectas-value-only branch June 21, 2026 16:57
@hstern hstern mentioned this pull request Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant